package com.yanqu.road.server.cmd.activity.doublespring.cross;

import com.yanqu.road.entity.activity.doublespring.enums.DoubleSpringLogInviteTypeEnum;
import com.yanqu.road.entity.log.doublespring.LogActivityDoubleSpringInvite;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DoubleSpringProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DOUBLE_SPRING_CANCEL_INVITE_FROM_CROSS,desc = "踏春游记-跨服返回-取消邀请")
public class DoubleSpringCancelInviteFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DoubleSpringProto.DoubleSpringCancelInviteCrossToServerMsg reqMsg = DoubleSpringProto.DoubleSpringCancelInviteCrossToServerMsg.parseFrom(packet.getBytes());
        if (reqMsg.getCancelUserIdCount() > 0) {
            //日志
            LogActivityDoubleSpringInvite log = new LogActivityDoubleSpringInvite();
            log.setActivityId(reqMsg.getActivityId());
            log.setUserId(player.getUserId());
            if (reqMsg.getCancelUserIdCount() > 1) {
                log.setInviteUserId(0);
                log.setType(DoubleSpringLogInviteTypeEnum.TYPE_CANCEL_INVITE_ONE_KEY.getType());
            } else {
                log.setInviteUserId(reqMsg.getCancelUserId(0));
                log.setType(DoubleSpringLogInviteTypeEnum.TYPE_CANCEL_INVITE.getType());
            }
            log.setCreateTime(System.currentTimeMillis());
            AutoLogMgr.add(log);
        }
        //返回
        DoubleSpringProto.DoubleSpringCancelInviteUserRespMsg.Builder respMsg = DoubleSpringProto.DoubleSpringCancelInviteUserRespMsg.newBuilder();
        respMsg.setRet(0);
        player.sendPacket(Protocol.U_DOUBLE_SPRING_CANCEL_INVITE, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
